package com.hzj.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hzj.pojo.Dict;
import com.hzj.service.DictService;
import com.hzj.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 组织架构表 前端控制器
 * </p>
 *
 * @author hzj
 * @since 2021-04-16
 */

@Api(tags = "医院管理类，一些crud")
@RestController
@RequestMapping("/provider/admin/cmn/dict")
@CrossOrigin
public class DictController {
    @Autowired
    DictService ds;

    @ApiOperation(value = "查询数据并判断是否有子类")
    @RequestMapping("/chiefAll/{id}")
    public Result chiefAll(@PathVariable int id) {
        List<Dict> childDict = ds.findChildDict(id);
        return Result.ok(childDict);
    }

    //查询所以省份
    @PostMapping("/findByDictCode/{dictCode}")
    public Result findByDictCode(@PathVariable String dictCode) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("dict_code", dictCode);
        Dict one = ds.getOne(wrapper);
        QueryWrapper wrapper1 = new QueryWrapper();
        wrapper1.eq("parent_id", one.getId());
        List list = ds.list(wrapper1);

        return Result.ok(list);

    }
    //根据省份id查询市
    @PostMapping("/findChildData/{id}")
    public Result findChildData(@PathVariable int id) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("parent_id", id);
        List list = ds.list(wrapper);
        return Result.ok(list);
    }

}

